/*
========================================================================
 Name        : LoginContainer.h
 Author      : shitou
 Copyright   : Your copyright notice
 Description : 
========================================================================
*/
#ifndef LOGINCONTAINER_H
#define LOGINCONTAINER_H

// [[[ begin generated region: do not modify [Generated Includes]
#include <coecntrl.h>		
// ]]] end generated region [Generated Includes]

// [[[ begin [Event Handler Includes]
// ]]] end [Event Handler Includes]

#include "CheckBox.h"
#include "CbaImage.h"
#include "HttpEngine.h"
#include "HttpEngine.h"
#include "GuiControlFactory.h"

// [[[ begin generated region: do not modify [Generated Forward Declarations]
class MEikCommandObserver;		
class CEikLabel;
class CEikEdwin;
class CEikSecretEditor;
// ]]] end generated region [Generated Forward Declarations]

/**
 * Container class for LoginContainer
 * 
 * @class	CLoginContainer LoginContainer.h
 */
class CLoginContainer : public CCoeControl, public MHTTPObserver
	{
public:
	// constructors and destructor
	CLoginContainer();
	static CLoginContainer* NewL( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver );
	static CLoginContainer* NewLC( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver );
	void ConstructL( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver );
	virtual ~CLoginContainer();

public:
	// from base class CCoeControl
	TInt CountComponentControls() const;
	CCoeControl* ComponentControl( TInt aIndex ) const;
	TKeyResponse OfferKeyEventL( 
			const TKeyEvent& aKeyEvent, 
			TEventCode aType );
	void HandleResourceChange( TInt aType );
	
public://from MHTTPObserver
	void HttpBodyReceived(TInt aError,const TDesC8& aBodyData,TInt aAction);
  
public:
   // user define
    void getUserName(TDes& aUserName);
    void setUserName(const TDesC& aUserName);
    void getPassword(TDes& aPassword);
    void setPassword(const TDesC& aPassword);
    TBool getRemberPassword();
    void setRemberPassword(TBool aValue);
    TBool getAutoLogin();
    void setAutoLogin(TBool aValue);
    TBool getBindMobile();
    void setBindMobile(TBool aValue);
    void Login();
    CHttpEngine* HttpEngine();
    
protected:
	// from base class CCoeControl
	void SizeChanged();

private:
	// from base class CCoeControl
	void Draw( const TRect& aRect ) const;

private:
	void SetControlsFocus(TInt aOrder); 
	
private:
	void QueryVerify();
	TInt Verify(const TDesC8& aText);
	void ConfirmLogin();
	TBool getUserNameandPassword(TDes& aUserName, TDes& aPassword);
	static TInt CancelNetWorkCallback(TAny* aThis);
	TInt getRandNum(TInt startNum, TInt endNum);
	HBufC8* stringToHex(const TDesC8& aValue);
	HBufC8* dealCodeUserInfo(const TDesC& aUseName,const TDesC& aPassword, int p);
	
private:
	void InitializeControlsL();
	void LayoutControls();
	CCoeControl* iFocusControl;
	MEikCommandObserver* iCommandObserver;
	
	// [[[ begin generated region: do not modify [Generated Methods]
public: 
	// ]]] end generated region [Generated Methods]
	
	// [[[ begin generated region: do not modify [Generated Type Declarations]
public: 
	// ]]] end generated region [Generated Type Declarations]
	
	// [[[ begin generated region: do not modify [Generated Instance Variables]
private: 
	CEikLabel* iLabel1;
	CEikEdwin* iUserName;
	CEikLabel* iLabel2;
	CEikSecretEditor* iPassword;
	// ]]] end generated region [Generated Instance Variables]
	CCheckBox* iRemeber;
	CCheckBox* iAutoLogin;
	CCheckBox* iHasBind;
	CTitleBar* iTitleBar;
	CEikImage* iInfoImage;
	CEikImage* iUserImage;
	CEikImage* iPassImage;
	CCbaImage* iCbaBar;
	CHttpEngine* iHttpEngine;
	// [[[ begin [Overridden Methods]
protected: 
	// ]]] end [Overridden Methods]
	
	
	// [[[ begin [User Handlers]
protected: 
	// ]]] end [User Handlers]
	
private:
	TInt iTabOrder;
	
public: 
	enum TControls
		{
		// [[[ begin generated region: do not modify [Generated Contents]
	    ETitleBar,
	    EInfoImage,
	    EUserImage,
	    EPassImage,
		ELabel1,
		ELabel2,
		EUserName,
		EPassword,
		// ]]] end generated region [Generated Contents]
		
		// add any user-defined entries here...
		ERemeberChk,
		EAutoLoginChk,
		EHasBindChk,
		ECbaBar,
		ELastControl
		};
	};
				
#endif // LOGINCONTAINER_H
